import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:top_foundation/utils/ex/color.dart';
import 'package:top_foundation/utils/theme/theme.dart';
import 'package:whale/helper/utils/util.dart';

class PushAnimatePage extends StatelessWidget {
  const PushAnimatePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: detailAppBar(context, title: '转场动画'),
      body: ListView(
        children: [
          ListTile(
            title: Text('replace（渐隐渐现）'),
            shape: UnderlineInputBorder(
              borderSide: ITheme.borderSide,
            ),
            trailing: Icon(
              Icons.keyboard_arrow_right,
              color: ITheme.contentColor,
            ),
            onTap: () {
              Navigator.of(context).pushReplacement(
                PageRouteBuilder(
                  pageBuilder: (context, animation, secondaryAnimation) =>
                      PopPage(text: 'replace（渐隐渐现）'),
                  transitionsBuilder:
                      (context, animation, secondaryAnimation, child) {
                    return FadeTransition(
                      opacity:
                          Tween<double>(begin: 0, end: 1).animate(animation),
                      child: child,
                    );
                  },
                  opaque: false,
                ),
              );
            },
          ),
          ListTile(
            title: Text('push（从左到右）'),
            shape: UnderlineInputBorder(
              borderSide: ITheme.borderSide,
            ),
            trailing: Icon(
              Icons.keyboard_arrow_right,
              color: ITheme.contentColor,
            ),
            onTap: () {
              Get.to(() => PopPage(text: 'push（从左到右）'));
            },
          ),
          ListTile(
            title: Text('push 从下往上'),
            shape: UnderlineInputBorder(
              borderSide: ITheme.borderSide,
            ),
            trailing: Icon(
              Icons.keyboard_arrow_right,
              color: ITheme.contentColor,
            ),
            onTap: () {
              Get.to(() => PopPage(text: 'push  从下往上'),
                  transition: Transition.downToUp, fullscreenDialog: true);
            },
          ),
          ListTile(
            title: Text('push 从上往下'),
            shape: UnderlineInputBorder(
              borderSide: ITheme.borderSide,
            ),
            trailing: Icon(
              Icons.keyboard_arrow_right,
              color: ITheme.contentColor,
            ),
            onTap: () {
              Get.to(() => PopPage(text: 'push  从上往下'),
                  transition: Transition.upToDown, fullscreenDialog: true);
            },
          ),
          ListTile(
            title: Text('push 渐隐渐现'),
            shape: UnderlineInputBorder(
              borderSide: ITheme.borderSide,
            ),
            trailing: Icon(
              Icons.keyboard_arrow_right,
              color: ITheme.contentColor,
            ),
            onTap: () {
              Get.to(() => PopPage(text: 'push  渐隐渐现'),
                  transition: Transition.fade, fullscreenDialog: true);
            },
          ),
          ListTile(
            title: Text('push 圆心放大'),
            shape: UnderlineInputBorder(
              borderSide: ITheme.borderSide,
            ),
            trailing: Icon(
              Icons.keyboard_arrow_right,
              color: ITheme.contentColor,
            ),
            onTap: () {
              Get.to(() => PopPage(text: 'push  圆心放大'),
                  transition: Transition.circularReveal,
                  fullscreenDialog: true);
            },
          ),
          ListTile(
            title: Text('push 放大缩小'),
            shape: UnderlineInputBorder(
              borderSide: ITheme.borderSide,
            ),
            trailing: Icon(
              Icons.keyboard_arrow_right,
              color: ITheme.contentColor,
            ),
            onTap: () {
              Get.to(() => PopPage(text: 'push  放大缩小'),
                  transition: Transition.zoom, fullscreenDialog: true);
            },
          ),
          ListTile(
            title: Text('push 上下放大'),
            shape: UnderlineInputBorder(
              borderSide: ITheme.borderSide,
            ),
            trailing: Icon(
              Icons.keyboard_arrow_right,
              color: ITheme.contentColor,
            ),
            onTap: () {
              Get.to(() => PopPage(text: 'push  上下放大'),
                  transition: Transition.size, fullscreenDialog: true);
            },
          ),
        ],
      ),
    );
  }
}

class PopPage extends StatelessWidget {
  const PopPage({super.key, required this.text});
  final String text;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: detailAppBar(context),
        backgroundColor: ColorEx.random,
        body: Center(
          child: Text(text),
        ));
  }
}
